package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.ProductModelingDao;
import com.tac.dao.mes.ProductModelingMaterialDao;
import com.tac.pojo.mes.ProductModeling;
import com.tac.pojo.mes.ProductModelingMaterial;
import com.tac.service.mes.ProductModelingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductModelingServiceImpl implements ProductModelingService {

    @Autowired
    private ProductModelingDao productModelingDao;

    @Autowired
    private ProductModelingMaterialDao productModelingMaterialDao;

    public Result<PageInfo<ProductModeling> > getList(Integer pageNum, Integer pageSize, String modelingName){
        PageHelper.startPage(pageNum,pageSize);
        List<ProductModeling> list = productModelingDao.getList(modelingName);
        PageInfo<ProductModeling> productModelingPageInfo = new PageInfo<>(list);
        return Result.success(productModelingPageInfo);
    }

    public Result remove(List<Integer> ids){
        Integer integer = productModelingDao.remove(ids);
        if(integer>0){
            return Result.success(null);
        }else {
            return Result.error("删除失败");
        }
    }

    public Result update(ProductModeling productModeling){
        Integer integer = productModelingDao.update(productModeling);
        if(integer>0){
            return Result.success(null);
        }else {
            return Result.error("更新失败");
        }
    }

    public Result save(ProductModeling productModeling){
        Integer integer = productModelingDao.save(productModeling);
        if(integer>0){
            return Result.success(productModeling);
        }else {
            return Result.error("添加失败");
        }
    }
    public Result remove2(List<Integer> ids){
        Integer integer = productModelingMaterialDao.remove(ids);
        if(integer>0){
            return Result.success(null);
        }else {
            return Result.error("删除失败");
        }
    }

    public Result update2(ProductModelingMaterial productModelingMaterial){
        Integer integer = productModelingMaterialDao.update(productModelingMaterial);
        if(integer>0){
            return Result.success(null);
        }else {
            return Result.error("更新失败");
        }
    }

    public Result save2(ProductModelingMaterial productModelingMaterial){
        Integer integer = productModelingMaterialDao.save(productModelingMaterial);
        if(integer>0){
            return Result.success(productModelingMaterial);
        }else {
            return Result.error("添加失败");
        }
    }
}
